package net.zjitc.servlet.test;

import org.apache.commons.io.IOUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/10/11.
 */
@WebServlet(name = "AServlet",urlPatterns = "/aServlet")
public class AServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response.setContentType("text/html;charset=utf-8");  //设置html解析 浏览器会把web.xml里的标签当成html标签解析,所以标签会消失
        PrintWriter out = response.getWriter();

        ServletContext context = this.getServletContext();
        InputStream in = context.getResourceAsStream("/WEB-INF/web.xml");

        out.write(IOUtils.toString(in,"utf-8"));
    }
}
